package swipe.painter;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import android.util.Range;

/* compiled from: ArrowPainter.kt */
public final class ArrowPainter extends Painter {
    private final Paint a;
    private final PointF c = new PointF();
    private final PointF d = new PointF();
    private final PointF e = new PointF();
    private final Path f = new Path();
    private final RectF g = new RectF();
    private PointF h = new PointF();
    private float i;
    private boolean isRight;

    public ArrowPainter() {
        this(false);
    }

    public ArrowPainter(boolean isRight) {
        this.isRight = isRight;
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(-1);
        paint.setAlpha(0);
        paint.setStyle(Style.STROKE);
        paint.setStrokeWidth(5.0f);
        paint.setStrokeCap(Cap.ROUND);
        paint.setStrokeJoin(Join.ROUND);
        this.a = paint;
    }

    public final RectF a() {
        return this.g;
    }

    public final PointF b() {
        return this.h;
    }

    public final void a(float f) {
        this.i = a(this, f, 0.4f, 0f, null, 8);
    }

    public final void reset() {
        this.a.setAlpha((int) (255f * this.i));
        e();
    }

    private void e() {
        float d = (((float) d()) * 0.015000001f) / 2.0f;
        float a = a(this, this.i, 0.5f, null, null, 12);
        if (this.i < 0.5f) {
            PointF pointF = this.e;
            pointF.x = 0;
            pointF.y = a * d;
        } else {
            double toRadians = Math.toRadians(((double) a) * 40.0d);
            PointF pointF2 = this.e;
            pointF2.x = ((float) Math.sin(toRadians)) * d;
            pointF2.y = ((float) Math.cos(toRadians)) * d;
        }
        this.c.set(this.e.x, -this.e.y);
        Path path = this.f;
        path.reset();
        path.moveTo(this.c.x, this.c.y);
        path.lineTo(this.d.x, this.d.y);
        path.lineTo(this.e.x, this.e.y);
        RectF rectF = this.g;
        rectF.left = this.d.x;
        rectF.top = this.c.y;
        rectF.right = this.c.x;
        rectF.bottom = this.e.y;
    }

    public void a(int i, int i2) {
        super.a(i, i2);
        e();
    }

    public void a(Canvas canvas) {
        float centerX = this.h.x - this.g.centerX();
        float f = this.h.y;
        int save = canvas.save();
        if (isRight) {
            canvas.scale(-1, 1, canvas.getWidth() / 2, canvas.getHeight() / 2);
        }
        canvas.translate(centerX, f);
        try {
            canvas.drawPath(this.f, this.a);
//            canvas.drawRect(a(), this.a);
        } finally {
            canvas.restoreToCount(save);
        }
    }

    static float a(ArrowPainter aVar, float f, float f2, Float f3, Float f4, int i) {
        return aVar.a(f, f2, (i & 4) != 0 ? null : f3, (i & 8) != 0 ? null : f4);
    }

    private final float a(float f, float f2, Float f3, Float f4) {
        Range<Float> range = Range.create(0f, 1f);
        if (range.contains(f) && range.contains(f2)) {
            return f < f2 ? f3 != null ? f3 : f / f2 : f4 != null ? f4 : (f - f2) / (((float) 1) - f2);
        } else {
            throw new IllegalArgumentException("Value must be 0 ~ 1");
        }
    }
}
